﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BestBuy.DAL
{
    public class cManageCategory
    {
        public static List<DanhMuc> GetChildrenOfCategory(int? parentID)
        {
            TradeKeyDataContext context = new TradeKeyDataContext();
            List<DanhMuc> list = new List<DanhMuc>();

            if (parentID.HasValue)
            {
                list = context.DanhMucs.Where(p => p.IDDanhMucCha == parentID).ToList();
            }
            else
            {
                list = context.DanhMucs.Where(p => !p.IDDanhMucCha.HasValue).ToList();
            }

            return list;
        }
        public static int countChildren(int id)
        {
            TradeKeyDataContext context = new TradeKeyDataContext();
            return context.DanhMucs.Where(p => p.IDDanhMucCha == id).ToList().Count;
        }
        public static string getNameCategory(int id)
        {
            TradeKeyDataContext context = new TradeKeyDataContext();
            return context.DanhMucs.Where(p => p.IDDanhMuc == id).FirstOrDefault().TenDanhMuc;
        }
    }
}